home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 7 / Apprentice-Release7.iso / Source Code / C / Applications / Moscow ML 1.42 / examples / calc / Lexer.lex < prev    next >
Encoding:
Text File  |  1997-08-18  |  561 b   |  22 lines  |  [TEXT/R*ch]

  1. {
  2. open Parser;        (* The token type is defined in Parser.sig *)
  3.  
  4. val intOfString = valOf o Int.fromString;
  5.  
  6. }
  7.  
  8. rule Token = parse
  9.     [` ` `\t`]     { Token lexbuf }     (* skip blanks *)
  10.   | [`\n` ]        { EOL }
  11.   | [`0`-`9`]+     { INT(intOfString (getLexeme lexbuf)) }
  12.   | `+`            { PLUS }
  13.   | `-`            { MINUS }
  14.   | `*`            { TIMES }
  15.   | `/`            { DIV }
  16.   | `(`            { LPAREN }
  17.   | `)`            { RPAREN }
  18.   | `~`            { UMINUS }
  19.   | eof            { EOF }
  20.   | _              { raise Fail "illegal symbol" }
  21. ;
  22.